package com.eliza.kotlin.design.creation.builder.demo2


/*-*- coding:utf-8 -*-
 * @Author  : debi
 * @Time    : 6/5/22
 * @Software: IntelliJ IDEA
 */
class Phone {

    private var cpu: String? = null
    private var screen: String? = null
    private var memory: String? = null
    private var mainboard: String? = null

    private constructor(builder: Builder) {
        cpu = builder.cpu
        screen = builder.screen
        memory = builder.memory
        mainboard = builder.mainboard
    }

    internal object Builder {
        var cpu: String? = null
        var screen: String? = null
        var memory: String? = null
        var mainboard: String? = null
        fun cpu(cpu: String): Phone.Builder {
            this.cpu = cpu
            return this
        }

        fun screen(screen: String): Phone.Builder {
            this.screen = screen
            return this
        }

        fun memory(memory: String): Phone.Builder {
            this.memory = memory
            return this
        }

        fun mainboard(mainboard: String): Phone.Builder {
            this.mainboard = mainboard
            return this
        }

        //使用构建者创建Phone对象
        fun build(): Phone {
            return Phone(this)
        }
    }

    override fun toString(): String {
        return "Phone(cpu=$cpu, screen=$screen, memory=$memory, mainboard=$mainboard)"
    }

}